package com.hzlx.exception.service.impl;

import java.util.Date;
import java.util.List;

import com.hzlx.MesMaintenanceTasksDtO;
import com.hzlx.exception.feign.EquipmentTaskService;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.hzlx.exception.mapper.ProductionAnomaliesMapper;
import com.hzlx.exception.domain.ProductionAnomalies;
import com.hzlx.exception.service.IProductionAnomaliesService;

/**
 * 生产异常记录Service业务层处理
 * 
 * @author dk
 * @date 2025-06-30
 */
@Service
public class ProductionAnomaliesServiceImpl implements IProductionAnomaliesService 
{
    @Autowired
    private ProductionAnomaliesMapper productionAnomaliesMapper;
    @Resource
     EquipmentTaskService equipmentTaskService;
    /**
     * 查询生产异常记录
     * 
     * @param anomalyId 生产异常记录主键
     * @return 生产异常记录
     */
    @Override
    public ProductionAnomalies selectProductionAnomaliesByAnomalyId(Long anomalyId)
    {
        return productionAnomaliesMapper.selectProductionAnomaliesByAnomalyId(anomalyId);
    }

    /**
     * 查询生产异常记录列表
     * 
     * @param productionAnomalies 生产异常记录
     * @return 生产异常记录
     */
    @Override
    public List<ProductionAnomalies> selectProductionAnomaliesList(ProductionAnomalies productionAnomalies)
    {
        return productionAnomaliesMapper.selectProductionAnomaliesList(productionAnomalies);
    }

    /**
     * 新增生产异常记录
     * 
     * @param productionAnomalies 生产异常记录
     * @return 结果
     */
   // private   MesMaintenanceTasksDtO mesMaintenanceTasksDtO ;
    @Override
    public int insertProductionAnomalies(ProductionAnomalies productionAnomalies)
    {
        MesMaintenanceTasksDtO mesMaintenanceTasksDtO = new MesMaintenanceTasksDtO();
          mesMaintenanceTasksDtO.setEquipmentId(productionAnomalies.getEquipmentId());
          mesMaintenanceTasksDtO.setTaskType(productionAnomalies.getAnomalyType());
          mesMaintenanceTasksDtO.setProblemDescription(productionAnomalies.getDescription());
          mesMaintenanceTasksDtO.setPriority(productionAnomalies.getSeverity());
          mesMaintenanceTasksDtO.setReportedBy(productionAnomalies.getReportedBy());
          mesMaintenanceTasksDtO.setReportedTime(productionAnomalies.getReportTime());
          mesMaintenanceTasksDtO.setTaskStatus(productionAnomalies.getStatus());
          mesMaintenanceTasksDtO.setAssignedToUserId(productionAnomalies.getResolvedBy());
          mesMaintenanceTasksDtO.setActualStartTime(null);
          mesMaintenanceTasksDtO.setActualEndTime(null);
            mesMaintenanceTasksDtO.setCreatedAt(new Date());
            mesMaintenanceTasksDtO.setUpdatedAt(new Date());
            equipmentTaskService.add(mesMaintenanceTasksDtO);
        return productionAnomaliesMapper.insertProductionAnomalies(productionAnomalies);
    }

    /**
     * 修改生产异常记录
     * 
     * @param productionAnomalies 生产异常记录
     * @return 结果
     */
    @Override
    public int updateProductionAnomalies(ProductionAnomalies productionAnomalies)
    {
        return productionAnomaliesMapper.updateProductionAnomalies(productionAnomalies);
    }

    /**
     * 批量删除生产异常记录
     * 
     * @param anomalyIds 需要删除的生产异常记录主键
     * @return 结果
     */
    @Override
    public int deleteProductionAnomaliesByAnomalyIds(Long[] anomalyIds)
    {
        return productionAnomaliesMapper.deleteProductionAnomaliesByAnomalyIds(anomalyIds);
    }

    /**
     * 删除生产异常记录信息
     * 
     * @param anomalyId 生产异常记录主键
     * @return 结果
     */
    @Override
    public int deleteProductionAnomaliesByAnomalyId(Long anomalyId)
    {
        return productionAnomaliesMapper.deleteProductionAnomaliesByAnomalyId(anomalyId);
    }
}
